using System;

namespace Refly.Cons
{
	using Refly.CodeDom;
	using Refly.CodeDom.Expressions;
	using Refly.CodeDom.Statements;
	using Refly.Templates;

	/// <summary>
	/// Summary description for SimpleDemo.
	/// </summary>
	public class SimpleDemo
	{
		public static void Output(NamespaceDeclaration ns)
		{
			// output result
			CodeGenerator gen = new CodeGenerator();

			// output to C#
			gen.Provider  = CodeGenerator.CsProvider;
			gen.GenerateCode("./CS",ns);

			// output to VB
			gen.Provider  = CodeGenerator.VbProvider;
			gen.GenerateCode("./VB",ns);
		}

		public static void CreateUser()
		{
			// create namespace
			NamespaceDeclaration ns = new NamespaceDeclaration("MyFirstNamespace");

			// adding imports

			// creating User class
			ClassDeclaration user = ns.AddClass("User");
			
			// put some comments
			user.Doc.Summary.AddText("Refly User class");
			user.Doc.Remarks.Add("para");
			user.Doc.Remarks.Into();
				user.Doc.Remarks.AddText("This class was generated by Refly");
			user.Doc.Remarks.OutOf();

			// adding private fields
			FieldDeclaration name = user.AddField(typeof(string),"name");
			FieldDeclaration lastName = user.AddField(typeof(string),"lastName");

			// adding properties for the fields
			PropertyDeclaration pname = user.AddProperty(name,true,true,true);
			PropertyDeclaration plastName = user.AddProperty(lastName,true,true,true);

			Output(ns);
		}	

		public static void CreateStronglyTypedCollection()
		{
			NamespaceDeclaration ns = new NamespaceDeclaration("Collections");

			CollectionTemplate st = new CollectionTemplate();
			st.ElementType = typeof(string).Name;
			st.NamespaceDeclaration=ns;

			st.Generate();

			Output(ns);
		}

		public static void CreateStronglyTypedDictionary()
		{
			NamespaceDeclaration ns = new NamespaceDeclaration("Collections");

			DictionaryTemplate st = new DictionaryTemplate();
			st.Key = typeof(string).Name;
			st.Value = typeof(int).Name;
			st.NamespaceDeclaration=ns;

			st.Generate();

			Output(ns);
		}

		public static void CreateStronglyTypedDataReader()
		{
			NamespaceDeclaration ns = new NamespaceDeclaration("Collections");

			DataReaderTemplate st = new DataReaderTemplate();
			st.Data.Name="User";
			st.Data.Fields.Add("name",typeof(string).FullName);
			st.Data.Fields.Add("lastname",typeof(string).FullName);
			st.NamespaceDeclaration=ns;
			st.Generate();

			Output(ns);
		}
	}
}
